package cn.itrip.trade.service;

import cn.itrip.beans.pojo.ItripHotelOrder;
import cn.itrip.dao.hotelorder.ItripHotelOrderMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;

    public ItripHotelOrder loadItripHotelOrder(String orderNo) throws Exception{
        Map<String,Object> param = new HashMap();
        param.put("orderNo",orderNo);
        List<ItripHotelOrder> result = itripHotelOrderMapper.getItripHotelOrderListByMap(param);
        if (result.size()>0){
            return result.get(0);
        }else
            return null;
    }

    public void paySuccess(String orderNo,int payType,String tradeNo) throws Exception{
        ItripHotelOrder order = this.loadItripHotelOrder(orderNo);
        order.setOrderStatus(2);
        order.setPayType(payType);
        order.setTradeNo(tradeNo);
        this.itripHotelOrderMapper.updateItripHotelOrder(order);

    }

    public void payFailed(String orderNo,int payType,String tradeNo) throws Exception{
        ItripHotelOrder order = this.loadItripHotelOrder(orderNo);
        order.setOrderStatus(1);
        order.setPayType(payType);
        order.setTradeNo(tradeNo);
        this.itripHotelOrderMapper.updateItripHotelOrder(order);
    }
}
